home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / system-config-printer / optionwidgets.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  8KB  |  197 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import gtk.glade as gtk
  5. import cups
  6. from gettext import gettext as _
  7. import ppdippstr
  8.  
  9. def OptionWidget(option, ppd, gui, tab_label = None):
  10.     '''Factory function'''
  11.     ui = option.ui
  12.     if ui == cups.PPD_UI_BOOLEAN and len(option.choices) != 2:
  13.         print 'Treating Boolean option %s as PickOne' % option.keyword
  14.         ui = cups.PPD_UI_PICKONE
  15.     
  16.     if ui == cups.PPD_UI_BOOLEAN:
  17.         return OptionBool(option, ppd, gui, tab_label = tab_label)
  18.     if ui == cups.PPD_UI_PICKONE:
  19.         return OptionPickOne(option, ppd, gui, tab_label = tab_label)
  20.     if ui == cups.PPD_UI_PICKMANY:
  21.         return OptionPickMany(option, ppd, gui, tab_label = tab_label)
  22.  
  23.  
  24. class Option:
  25.     
  26.     def __init__(self, option, ppd, gui, tab_label = None):
  27.         self.option = option
  28.         self.ppd = ppd
  29.         self.gui = gui
  30.         self.enabled = True
  31.         self.tab_label = tab_label
  32.         vbox = gtk.VBox()
  33.         self.btnConflict = gtk.Button()
  34.         icon = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_SMALL_TOOLBAR)
  35.         self.btnConflict.add(icon)
  36.         self.btnConflict.set_no_show_all(True)
  37.         vbox.add(self.btnConflict)
  38.         self.conflictIcon = vbox
  39.         self.btnConflict.connect('clicked', self.on_btnConflict_clicked)
  40.         icon.show()
  41.         self.constraints = _[1]
  42.         self.conflicts = set()
  43.         self.conflict_message = ''
  44.  
  45.     
  46.     def enable(self, enabled = True):
  47.         self.selector.set_sensitive(enabled)
  48.         self.enabled = enabled
  49.  
  50.     
  51.     def disable(self):
  52.         self.enable(False)
  53.  
  54.     
  55.     def is_enabled(self):
  56.         return self.enabled
  57.  
  58.     
  59.     def get_current_value(self):
  60.         raise NotImplemented
  61.  
  62.     
  63.     def is_changed(self):
  64.         return self.get_current_value() != self.option.defchoice
  65.  
  66.     
  67.     def writeback(self):
  68.         if self.enabled:
  69.             self.ppd.markOption(self.option.keyword, self.get_current_value())
  70.         
  71.  
  72.     
  73.     def checkConflicts(self, update_others = True):
  74.         value = self.get_current_value()
  75.         for constraint in self.constraints:
  76.             if constraint.option1 == self.option.keyword:
  77.                 option2 = self.gui.options.get(constraint.option2, None)
  78.                 choice1 = constraint.choice1
  79.                 choice2 = constraint.choice2
  80.             else:
  81.                 option2 = self.gui.options.get(constraint.option1, None)
  82.                 choice1 = constraint.choice2
  83.                 choice2 = constraint.choice1
  84.             if option2 is None:
  85.                 continue
  86.             
  87.             if choice1 == value and option2.get_current_value() == choice2:
  88.                 self.conflicts.add(constraint)
  89.                 if update_others:
  90.                     option2.checkConflicts(update_others = False)
  91.                 
  92.             update_others
  93.             if constraint in self.conflicts:
  94.                 self.conflicts.remove(constraint)
  95.                 option2.checkConflicts(update_others = False)
  96.                 continue
  97.         
  98.         tooltip = [
  99.             _('Conflicts with:')]
  100.         for c in self.conflicts:
  101.             if c.option1 == self.option.keyword:
  102.                 option = self.gui.options.get(c.option2)
  103.             else:
  104.                 option = self.gui.options.get(c.option1)
  105.             tooltip.append(option.option.text)
  106.         
  107.         tooltip = '\n'.join(tooltip)
  108.         self.conflict_message = tooltip
  109.         if self.conflicts:
  110.             self.btnConflict.set_tooltip_text(tooltip)
  111.             self.btnConflict.show()
  112.         else:
  113.             self.btnConflict.hide()
  114.         self.gui.option_changed(self)
  115.         return self.conflicts
  116.  
  117.     
  118.     def on_change(self, widget):
  119.         self.checkConflicts()
  120.  
  121.     
  122.     def on_btnConflict_clicked(self, button):
  123.         parent = self.btnConflict
  124.         while parent != None and not isinstance(parent, gtk.Window):
  125.             parent = parent.get_parent()
  126.         dialog = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, self.conflict_message)
  127.         dialog.run()
  128.         dialog.destroy()
  129.  
  130.  
  131.  
  132. class OptionBool(Option):
  133.     
  134.     def __init__(self, option, ppd, gui, tab_label = None):
  135.         self.selector = gtk.CheckButton(ppdippstr.ppd.get(option.text))
  136.         self.label = None
  137.         self.false = u'False'
  138.         self.true = u'True'
  139.         for c in option.choices:
  140.             if c['choice'] in ('None', 'False', 'Off'):
  141.                 self.false = c['choice']
  142.             
  143.             if c['choice'] in ('True', 'On'):
  144.                 self.true = c['choice']
  145.                 continue
  146.         
  147.         self.selector.set_active(option.defchoice == self.true)
  148.         self.selector.set_alignment(0, 0.5)
  149.         self.selector.connect('toggled', self.on_change)
  150.         Option.__init__(self, option, ppd, gui, tab_label = tab_label)
  151.  
  152.     
  153.     def get_current_value(self):
  154.         return (self.false, self.true)[self.selector.get_active()]
  155.  
  156.  
  157.  
  158. class OptionPickOne(Option):
  159.     widget_name = 'OptionPickOne'
  160.     
  161.     def __init__(self, option, ppd, gui, tab_label = None):
  162.         self.selector = gtk.combo_box_new_text()
  163.         label = ppdippstr.ppd.get(option.text)
  164.         if not label.endswith(':'):
  165.             label += ':'
  166.         
  167.         self.label = gtk.Label(label)
  168.         self.label.set_alignment(0, 0.5)
  169.         selected = None
  170.         for nr, choice in enumerate(option.choices):
  171.             self.selector.append_text(ppdippstr.ppd.get(choice['text']))
  172.             if option.defchoice == choice['choice']:
  173.                 selected = nr
  174.                 continue
  175.         
  176.         if selected is not None:
  177.             self.selector.set_active(selected)
  178.         else:
  179.             print option.text, 'unknown value:', option.defchoice
  180.         self.selector.connect('changed', self.on_change)
  181.         Option.__init__(self, option, ppd, gui, tab_label = tab_label)
  182.  
  183.     
  184.     def get_current_value(self):
  185.         return self.option.choices[self.selector.get_active()]['choice']
  186.  
  187.  
  188.  
  189. class OptionPickMany(OptionPickOne):
  190.     widget_name = 'OptionPickMany'
  191.     
  192.     def __init__(self, option, ppd, gui, tab_label = None):
  193.         raise NotImplemented
  194.         Option.__init__(self, option, ppd, gui, tab_label = tab_label)
  195.  
  196.  
  197.